package cn.zyx.Config;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
 * @author zzp
 * @since 2021/12/18 18:34
 */
@Component
@PropertySource("classpath:wx.properties")
public class WeixinLoginProperties implements InitializingBean {//InitializingBean 初始化bean
    @Value("${weixin.login.info.gateway}")
    private String gateway;
    @Value("${weixin.login.info.appid}")
    private String appid;
    @Value("${weixin.login.info.appsecret}")
    private String appsecret;
    @Value("${weixin.login.info.redirectUrl}")
    private String redirectUrl;

    public static String WX_OPEN_GATEWAY;
    public static String WX_OPEN_APP_ID;
    public static String WX_OPEN_APP_SECRET;
    public static String WX_OPEN_REDIRECT_URL;

    //Spirng的InitializingBean为bean提供了定义初始化方法的方式。InitializingBean是一个接口，它仅仅包含一个方法：afterPropertiesSet()。
    //Bean实现这个接口，在afterPropertiesSet()中编写初始化代码：
    @Override
    public void afterPropertiesSet() throws Exception {
        WX_OPEN_GATEWAY = gateway;
        WX_OPEN_APP_ID = appid;
        WX_OPEN_APP_SECRET = appsecret;
        WX_OPEN_REDIRECT_URL = redirectUrl;
    }

}
